package com.zl.convertd.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.zl.convertd.enums.DateConverterTypeEnum;
import com.zl.convertd.executors.DatePopupExecutor;

import java.util.List;
import java.util.Objects;

/**
 * @Description
 * @Author zl
 * @Date 2024/7/4 18:03
 */
public class DataConverter extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        Editor editor = (Editor) e.getDataContext().getData("editor");
        Project project = e.getProject();
        List<String> typeNameList = DateConverterTypeEnum.getTypeNameList();
        // 创建列表弹出窗口
        ListPopup listPopup = JBPopupFactory.getInstance()
                .createListPopup(new DatePopupExecutor("Date Converter",typeNameList,editor,project));
        // 在屏幕中间显示列表弹出窗口
        listPopup.showCenteredInCurrentWindow(Objects.requireNonNull(e.getProject()));
    }
}
